package com.timoon.sample.web.nav;

import java.util.Arrays;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;

import com.timoon.app.utils.Constantor;
import com.timoon.component.panel.jlayout.JLayouterPanel;
import com.timoon.component.panel.nav.AbstractNavLink;
import com.timoon.component.panel.nav.AbstractNavPanel;
import com.timoon.component.panel.nav.ResourceMapper;
import com.timoon.component.panel.tabspanel.TabsPanel;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class NavigatorPanel extends AbstractNavPanel{
	private static final long serialVersionUID = -727309150343534233L;
	
	private ResourceMapper mapper;
	
	
	@SuppressWarnings("unchecked")
	public NavigatorPanel(String id) {
		super(id,Arrays.asList("product","system","sample"));
		// TODO Auto-generated constructor stub
		
	}
	@Override
	protected AbstractNavLink getNavLink(final String code,final Label span){
		
		if(this.mapper==null){
			mapper=(ResourceMapper) this.getSession().getAttribute(Constantor.SESSION_USER_MAPPER);
		}
		
		AbstractNavLink link=new AbstractNavLink("wk_menu", JLayouterPanel.CENTER_PANEL){
			@Override
			protected Panel getPanel() {
				// TODO Auto-generated method stub
				/*单击左边菜单
				 * center区域都返回tabsPanel
				 * 但是注入点击菜单的子code集合,tabsPanel会根据codes利用session里的mapper查找出panel
				 * */
				TabsPanel tabsPanel=new TabsPanel(JLayouterPanel.CENTER_PANEL, mapper.getChildCodeByCode(code));
				return tabsPanel;
			}
			@Override
			public void onClick(AjaxRequestTarget arg0) {
				// TODO Auto-generated method stub
				super.onClick(arg0);
				changeSpanStyle(arg0,span);
			}
		};
		
		return link;
	}

}
